home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Procedure to send/receive things to the PK232 in block mode *)
- (* *)
- (* Copyright 1988, 1989, 1990 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- PROCEDURE pk232_io;
-
- TYPE
- over_array = ARRAY[1..512] OF BYTE;
-
- VAR
-
- byte_array : ^over_array;
- byte_count : WORD;
- set_dx : BYTE;
- times_up : LONGINT;
- tnc_registers : REGISTERS;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* If this is master task then time check *)
- (*-----------------------------------------------------------------------*)
-
- IF master_thread THEN
- time_check;
-
- (*-----------------------------------------------------------------------*)
- (* Save the COM number for later use *)
- (*-----------------------------------------------------------------------*)
-
- set_dx := active_port^.com_number - 1;
-
- (*-----------------------------------------------------------------------*)
- (* Ok. Get addressing for transmit *)
- (*-----------------------------------------------------------------------*)
-
- WITH active_tcb^.tnc_htt^, tnc_registers DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* See if junk around? *)
- (*-------------------------------------------------------------------*)
-
- AX := $0300;
- DX := set_dx;
-
- signal_place^ := $0200 + LO(signal_place^);
-
- INTR(tnc_interrupt, tnc_registers);
-
- signal_place^ := $F800 + LO(signal_place^);
-
- AH := AH AND lsr_8250_dr;
- IF AH <> 0 THEN
- window_write_critical('Garbage from TNC -- '
- + active_tcb^.port_chan_s
- + ' -- ',
- garbage_collect_tnc);
-
- (*-------------------------------------------------------------------*)
- (* Transmit it! *)
- (*-------------------------------------------------------------------*)
-
- AX := $0A00;
- CX := pk232_len;
- DX := set_dx;
- DI := OFS(pk232_buff^);
- ES := SEG(pk232_buff^);
-
- signal_place^ := $0100 + LO(signal_place^);
-
- INTR(tnc_interrupt, tnc_registers);
-
- signal_place^ := $7800 + LO(signal_place^);
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* If outgoing data then we are done *)
- (*-----------------------------------------------------------------------*)
-
- IF tnc_cmd_data = info_cmd_info THEN
- EXIT;
-
- (*-----------------------------------------------------------------------*)
- (* Ok. Get addressing for receive *)
- (*-----------------------------------------------------------------------*)
-
- WITH active_tcb^.tnc_tth^, tnc_registers DO
- BEGIN;
-
- byte_count := 0;
-
- times_up := up_time + time_out_value;
-
- (*-------------------------------------------------------------------*)
- (* Initialize *)
- (*-------------------------------------------------------------------*)
-
- CX := SIZEOF(pk232_buff^);
- DI := OFS(pk232_buff^);
- ES := SEG(pk232_buff^);
-
- byte_array := @pk232_buff^;
- byte_count := 0;
-
- (*-------------------------------------------------------------------*)
- (* Loop reading the data *)
- (*-------------------------------------------------------------------*)
-
- WHILE TRUE DO
- BEGIN;
-
- task_switch;
-
- (*---------------------------------------------------------------*)
- (* Receive it *)
- (*---------------------------------------------------------------*)
-
- AX := $0B00;
- CX := SIZEOF(pk232_buff^) - byte_count;
- DX := set_dx;
-
- signal_place^ := $0200 + LO(signal_place^);
-
- INTR(tnc_interrupt, tnc_registers);
-
- signal_place^ := $F800 + LO(signal_place^);
-
- byte_count := byte_count + CX;
-
- (*---------------------------------------------------------------*)
- (* Check for overrun *)
- (*---------------------------------------------------------------*)
-
- IF (AH AND lsr_8250_or) <> 0 THEN
- BEGIN;
- window_write_critical_i('Overrun in block loop -- '
- + active_tcb^.port_chan_s
- + ' -- Count = ',
- byte_count);
- IF p_type = port_aeapk232 THEN
- BEGIN;
- IF byte_count <= 5 THEN
- WHILE byte_count <= 10 DO
- BEGIN;
- INC(byte_count);
- byte_array^[byte_count] := $0;
- END;
- EXIT;
- END;
- END;
-
- (*---------------------------------------------------------------*)
- (* Check for clock update need *)
- (*---------------------------------------------------------------*)
-
- IF master_thread THEN
- time_check;
-
- (*---------------------------------------------------------------*)
- (* Check for time out *)
- (*---------------------------------------------------------------*)
-
- IF (times_up <= up_time) AND (CX = 0) THEN
- BEGIN;
- window_write_critical_i('Timeout in block loop -- '
- + active_tcb^.port_chan_s
- + ' -- Count = ',
- byte_count);
- IF byte_count <= 5 THEN
- WHILE byte_count <= 10 DO
- BEGIN;
- INC(byte_count);
- byte_array^[byte_count] := $0;
- END;
- EXIT;
- END;
-
- (*---------------------------------------------------------------*)
- (* See if end yet *)
- (*---------------------------------------------------------------*)
-
- IF byte_count >= 2 THEN
- BEGIN;
-
- (*-----------------------------------------------------------*)
- (* Watch for weirdos *)
- (*-----------------------------------------------------------*)
-
- IF byte_count > SIZEOF(over_array) THEN
- BEGIN;
- window_write_critical_i('Buffer overrun on '
- + active_tcb^.port_chan_s
- + ' -- Count = ',
- byte_count);
- byte_array^[1] := 0;
- byte_count := 1;
- END;
-
- (*-----------------------------------------------------------*)
- (* Look for ETB *)
- (*-----------------------------------------------------------*)
-
- IF (byte_array^[byte_count] = ORD(etb)) AND
- (byte_array^[byte_count-1] <> ORD(dle)) THEN
- BEGIN;
- pk232_len := byte_count;
- EXIT;
- END;
-
- END;
-
- END; (*----- End loop for receiving the response ------------------*)
-
- END;
-
- END;